<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      lang="en-us"
      xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->

    <title> 新闻后台管理 </title>
    <meta name="description" content=""/>
    <meta name="author" content=""/>

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>

    <!-- Basic Styles -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/bootstrap.min.css"
          th:href="@{/resources/css/bootstrap.min.css}"/>
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/font-awesome.min.css"
          th:href="@{/resources/css/font-awesome.min.css}"/>

    <!-- SmartAdmin Styles : Caution! DO NOT change the order -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-production-plugins.min.css"
          th:href="@{/resources/css/smartadmin-production-plugins.min.css}"/>
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-production.min.css"
          th:href="@{/resources/css/smartadmin-production.min.css}"/>
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-skins.min.css"
          th:href="@{/resources/css/smartadmin-skins.min.css}"/>

    <!-- SmartAdmin RTL Support -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../static/css/smartadmin-rtl.min.css"
          th:href="@{/resources/css/smartadmin-rtl.min.css}"/>

    <!-- FAVICONS -->
    <link rel="shortcut icon" href="../../static/img/favicon/favicon.ico" type="image/x-icon"
          th:href="@{/resources/img/favicon/favicon.ico}"/>
    <link rel="icon" href="../../static/img/favicon/favicon.ico" type="image/x-icon"
          th:href="@{/resources/img/favicon/favicon.ico}"/>

    <style rel="stylesheet">
        .active {
            class: fa-arrow-up
            text:
        }
    </style>

</head>

<body class="">

<!-- HEADER -->
<header id="header">
    <div id="logo-group">

        <!-- PLACE YOUR LOGO HERE -->
        <span id="logo"><a th:href="@{/}"> <img th:src="@{/resources/img/logo.png}" alt="logo"/></a></span>
        <!-- END LOGO PLACEHOLDER -->

    </div>

    <!-- pulled right: nav area -->
    <div class="pull-right">

        <!-- collapse menu button -->
        <div id="hide-menu" class="btn-header pull-right">
            <span> <a href="javascript:void(0);" data-action="toggleMenu" title="Collapse Menu"><i
                    class="fa fa-reorder">隐藏</i></a> </span>
        </div>
        <!-- end collapse menu -->

        <!-- logout button -->
        <div id="logout" class="btn-header transparent pull-right">
            <span> <a th:href="@{/logout}" title="登出" data-action="userLogout" data-logout-msg="您确定要退出登录吗?"><i
                    class="fa fa-sign-out">退出</i></a> </span>
        </div>
        <!-- end logout button -->

        <!-- fullscreen button -->
        <div id="fullscreen" class="btn-header transparent pull-right">
            <span> <a href="javascript:void(0);" data-action="launchFullscreen" title="全屏"><i class="fa fa-arrows-alt">全屏</i></a> </span>
        </div>
        <!-- end fullscreen button -->
        <!-- home button -->
        <div id="home" class="btn-header transparent pull-right">
            <span> <a th:href="@{/}" title="回到首页"><i class="fa fa-home">首页</i></a> </span>
        </div>
        <!-- end home button -->

    </div>
    <!-- end pulled right: nav area -->

</header>
<!-- END HEADER -->

<!-- Left panel : Navigation area -->
<aside id="left-panel">
    <nav>
        <ul>
            <li>
                <a th:href="@{/}">
                    <i class="fa fa-lg fa-book"></i>
                    <span class="menu-item-parent fa-lg">首页</span>
                </a>
            </li>
            <li>
                <a href="javascript:">
                    <i class="fa fa-lg fa-book"></i>
                    <span class="menu-item-parent fa-lg">频道管理</span>
                </a>
                <ul>
                    <li>
                        <a th:href="@{/channel/setting}">
                            <i class="fa fa-lg fa-edit"></i>
                            <span class="menu-item-parent fa-lg">频道管理</span>
                        </a>
                    </li>
                    <hr>
                    <li th:each="channel : ${channels}"
                        th:attrappend="data-channel-id=${channel.channel_id}" class="channelLi">
                        <a href="javascript:">
                            <i class="fa fa-lg fa-edit"></i>
                            <span class="menu-item-parent fa-lg" th:text="${channel.title}">频道</span>
                        </a>
                    </li>
                </ul>
            </li>
            <li class="active">
                <a th:href="@{/article/list}">
                    <i class="fa fa-lg fa-book"></i>
                    <span class="menu-item-parent fa-lg">新闻管理</span>
                </a>
            </li>

        </ul>
    </nav>
</aside>
<!-- END NAVIGATION -->

<!-- MAIN PANEL -->
<div id="main" role="main">

    <!-- RIBBON -->
    <div id="ribbon">

        <!-- breadcrumb -->
        <ol class="breadcrumb">
            <i class="fa fa-arrow-right"></i>
            <li class="fa fa-lg" th:text="新闻管理">新闻管理</li>
        </ol>

    </div>
    <!-- END RIBBON -->

    <!-- MAIN CONTENT -->
    <div id="content">

        <!-- row -->
        <div class="row">

            <!-- widget grid -->
            <section id="widget-grid" class="">

                <!-- row -->
                <div class="row">

                    <article class="col-xs-12 col-sm-12">

                        <!-- Widget ID (each widget will need unique ID)-->
                        <div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-1"
                             data-widget-colorbutton="false"
                             data-widget-deletebutton="false" data-widget-editbutton="false">
                            <header>
                                <span class="widget-icon"> <i class="fa fa-table"></i> </span>

                                <h2>新闻列表</h2>

                            </header>

                            <!-- widget div-->
                            <div>
                                <!-- widget content -->
                                <div class="widget-body">

                                    <form class="smart-form" id="mainForm">

                                        <header>所有新闻</header>

                                        <fieldset>
                                            <div class="row">
                                                <section class="col col-4">
                                                    <div class="form-group">
                                                        <div class="col-xs-9 col-lg-6 inputGroupContainer">
                                                            <div class="input-group">
                                                                <input type="text" class="form-control"
                                                                       th:value="${queryKey}" name="queryKey"
                                                                       placeholder="搜索标题..."/>
                                                                <span class="input-group-addon" id="searchBtn"><i
                                                                        class="fa fa-search"></i></span>
                                                            </div>
                                                        </div>
                                                    </div>


                                                </section>


                                                <section class="col col-4">
                                                    <div class="form-group">

                                                        <label class="select">
                                                            <select class="input font-md" id="select_column"
                                                                    name="column_id">
                                                                <option value="0">请选择频道和栏目</option>
                                                                <div th:each="channel : ${channels}">
                                                                    <option class="columnOption"
                                                                            th:each="column : ${channel.columns}"
                                                                            th:value="${column.column_id}"
                                                                            th:text="${channel.title}+' - '+ ${column.title}"
                                                                    >频道 - 栏目
                                                                    </option>
                                                                </div>

                                                            </select><i></i>
                                                        </label>
                                                    </div>


                                                </section>


                                            </div>

                                            <div class="table-responsive">
                                                <table class="table table-bordered ">
                                                    <thead>
                                                    <tr>
                                                        <th style="text-align:center;width:4%"><input type="checkbox"
                                                                                                      id="check_all"
                                                                                                      onclick="checkAllRows()"
                                                                                                      title="全选"/></th>
                                                        <th>新闻编号</th>
                                                        <th>新闻标题</th>
                                                        <th>来源</th>
                                                        <th>创建日期</th>
                                                        <th>操作</th>
                                                    </tr>
                                                    </thead>
                                                    <tbody>
                                                    <tr th:each="article : ${articles}"
                                                        th:id="'article'+${article.article_id}">
                                                        <th style="text-align: center;width:4%;">
                                                            <input type="checkbox" name="check_single_row"
                                                                   onclick="cancelCheckAllStatus()"
                                                                   th:value="${article.article_id}"/>
                                                        </th>
                                                        <td th:text="${article.article_id}"></td>
                                                        <td th:text="${article.title}"></td>
                                                        <td th:text="${article.source}"></td>
                                                        <td th:text="${article.dateTimeStr}"></td>
                                                        <td>
                                                            <label class="fa fa-edit edit-news-btn"
                                                                   th:attr="data-news-id=${article.article_id}">编辑</label>
                                                        </td>
                                                    </tr>
                                                    </tbody>
                                                </table>
                                            </div>

                                        </fieldset>

                                        <footer>
                                            <!-- 添加按钮 -->
                                            <button type="button" href="javascript:" id="addNewsBtn"
                                                    class="btn btn-info">
                                                <i class="fa fa-plus"></i>
                                                新增
                                            </button>
                                            <button type="button" id="delete_btn"
                                                    href="javascript:" class="btn btn-danger">
                                                <i class="fa fa-trash-o"></i>
                                                删除
                                            </button>
                                            <!-- 刷新按钮 -->
                                            <button type="button" id="refresh_btn" type="button"
                                                    href="javascript:" class="btn btn-success">
                                                <i class="fa fa-refresh"></i>
                                                刷新
                                            </button>

                                        </footer>

                                    </form>


                                </div>
                                <!-- end widget content -->

                            </div>
                            <!-- end widget div -->

                        </div>
                        <!-- end widget -->

                    </article>

                </div>

                <!-- end row -->

            </section>
            <!-- end widget grid -->

        </div>


    </div>
    <!-- END MAIN CONTENT -->

</div>
<!-- END MAIN PANEL -->

<!-- PAGE FOOTER -->
<div class="page-footer">

</div>
<!-- END PAGE FOOTER -->


<!--================================================== -->

<script src="../../static/js/libs/jquery-2.1.1.min.js" th:src="@{/resources/js/libs/jquery-2.1.1.min.js}"></script>

<script src="../../static/js/libs/jquery-ui-1.10.3.min.js"
        th:src="@{/resources/js/libs/jquery-ui-1.10.3.min.js}"></script>

<!-- IMPORTANT: APP CONFIG -->
<script src="../../static/js/app.config.js" th:src="@{/resources/js/app.config.js}"></script>

<!-- BOOTSTRAP JS -->
<script src="../../static/js/bootstrap/bootstrap.min.js" th:src="@{/resources/js/bootstrap/bootstrap.min.js}"></script>

<!-- JARVIS WIDGETS -->
<script src="../../static/js/smartwidgets/jarvis.widget.min.js"
        th:src="@{/resources/js/smartwidgets/jarvis.widget.min.js}"></script>

<script src="../../static/js/notification/SmartNotification.min.js"
        th:src="@{/resources/js/notification/SmartNotification.min.js}"></script>

<!-- JQUERY VALIDATE -->
<script src="../../static/js/plugin/jquery-validate/jquery.validate.min.js"
        th:src="@{/resources/js/plugin/jquery-validate/jquery.validate.min.js}"></script>

<!-- JQUERY MASKED INPUT -->
<script src="../../static/js/plugin/masked-input/jquery.maskedinput.min.js"
        th:src="@{/resources/js/plugin/masked-input/jquery.maskedinput.min.js}"></script>

<!-- JQUERY SELECT2 INPUT -->
<script src="../../static/js/plugin/select2/select2.min.js"
        th:src="@{/resources/js/plugin/select2/select2.min.js}"></script>

<!--[if IE 8]>

<h1>Your browser is out of date, please update your browser by going to www.microsoft.com/download</h1>

<![endif]-->

<!-- MAIN APP JS FILE -->
<script src="../../static/js/app.min.js" th:src="@{/resources/js/app.min.js}"></script>
<script src="../../static/js/plugin/jquery-nestable/jquery.nestable.min.js"
        th:src="@{/resources/js/plugin/jquery-nestable/jquery.nestable.min.js}"></script>


<script th:inline="javascript">
    /*<![CDATA[*/

    function checkAllRows() {
        var if_checked = document.getElementById("check_all").checked;
        var boxs = document.getElementsByName("check_single_row");
        for (var i = 0; i < boxs.length; i++) {
            boxs[i].checked = if_checked;
        }
    }

    function cancelCheckAllStatus() {

        var boxs = document.getElementsByName("check_single_row");
        var flag = true;
        for (var i = 0; i < boxs.length; i++) {
            if (boxs[i].checked == false) {
                flag = false;
                break;
            }
        }
        document.getElementById("check_all").checked = flag;
    }


    // DO NOT REMOVE : GLOBAL FUNCTIONS!
    $(document).ready(function () {

        pageSetUp();

//        localStorage.clear();


        $('#addNewsBtn').click(function () {
            var url = "";
            /*[+
             url = [[@{/article/append}]];
             +]*/
            location.href = url;
        });

        /*[+
         $('#select_column').val([[${column_id}]]);
         +]*/

        $('#searchBtn').click(function () {
            $('#mainForm').submit();
        });

        $('#select_column').on('change', function () {
            $('#mainForm').submit();
        })

        $('.edit-news-btn').click(function () {
            var article_id = $(this).data("news-id");
            var url = "";
            /*[+
             url = [[@{/article/toEdit}]];
             +]*/
            location.href = url + "?article_id=" + article_id;
        })


        $(".channelLi").click(function () {
            var url = /*[[@{/channel/toEdit}]]*/"";
            var channel_id = $(this).data("channel-id");
            window.location.href = url + "?channel_id=" + channel_id;
        });

        $("#delete_btn").click(function () {
            var url = /*[[@{/article/delete}]]*/"";
            var checked_ids = "";
            $("[name='check_single_row']:checked").each(function () {
                checked_ids += "," + $(this).val();
            });

            if (checked_ids.length == 0) {
                alert("您还没有选中要删除的项目");
                return;
            } else {
                checked_ids = checked_ids.substring(1);
            }

            var result = window.confirm("确认删除选中的项目?");
            if (result == false) {
                return;
            }

            $.post(url, {deleteIds: checked_ids}, function (data) {
                if (data.code == 1) {
                    location.reload();
//                    var ids = data.ids;
//                    for (var i in ids) {
//                        $("#col" + ids[i]).remove();
//                    }
                }
            }); // end post
        }); // end click func

        $("#refresh_btn").click(function () {

            location.reload();
        });
    });

    /*]]>*/

</script>


</body>

</html>